package com.example.demo.auth.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.example.demo.auth.entity.UpUser;
import com.example.demo.auth.service.UpUserService;

@Service("upUserService")
public class UpUserServiceImpl implements UpUserService {
	@Autowired
    private JdbcTemplate jdbcTemplate;

    public UpUser getUser(long nid) {
    	UpUser upUser;
        String sql = "SELECT U.NID, U.ID, U.NAME, U.ACCOUNT, U.PASSWORD,\n" + 
        		"       U.DESCRIPTION, U.ACCOUNT_ENABLE, U.ACCOUNT_LOCKED,\n" + 
        		"       U.ACCOUNT_LOCKED_REASON, U.SEX, U.BIRTHDATE, U.CREDENTIALS_TYPE,\n" + 
        		"       U.CREDENTIALS_NUMBER, U.EMAIL, U.MOBILE_TELEPHONE, U.OFFICE_TELEPHONE,\n" + 
        		"       U.FAX, U.CREATED_BY, U.CREATION_DATE, U.LAST_UPDATED_BY,\n" + 
        		"       U.LAST_UPDATE_DATE, U.ACTIVE_FLAG, U.ORDER_NUM\n" + 
        		"  FROM V_IDM_USER U\n" + 
        		" WHERE U.ACTIVE_FLAG = 'T'\n" + 
        		"   AND U.NID = ?";
        upUser = jdbcTemplate.queryForObject(sql.toString(), UpUser.class,nid);
        return upUser;
    }

    public UpUser getUserByLoginName(String loginName) {
    	UpUser upUser;
        String sql = "SELECT U.NID, U.ID, U.NAME, U.ACCOUNT, U.PASSWORD,\n" + 
        		"       U.DESCRIPTION, U.ACCOUNT_ENABLE, U.ACCOUNT_LOCKED,\n" + 
        		"       U.ACCOUNT_LOCKED_REASON, U.SEX, U.BIRTHDATE, U.CREDENTIALS_TYPE,\n" + 
        		"       U.CREDENTIALS_NUMBER, U.EMAIL, U.MOBILE_TELEPHONE, U.OFFICE_TELEPHONE,\n" + 
        		"       U.FAX, U.CREATED_BY, U.CREATION_DATE, U.LAST_UPDATED_BY,\n" + 
        		"       U.LAST_UPDATE_DATE, U.ACTIVE_FLAG, U.ORDER_NUM\n" + 
        		"  FROM V_IDM_USER U\n" + 
        		" WHERE U.ACTIVE_FLAG = 'T'\n" + 
        		"   AND U.ACCOUNT = ?";
        
        upUser = jdbcTemplate.queryForObject(sql.toString(), UpUser.class, loginName);
        return upUser;
        
    }
}
